#include <FastLED.h>
#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ESP8266WebServer.h>
#include <FS.h>
#include <Ticker.h>
#include <DNSServer.h>

#define NUM_LEDS 12
#define DATA_PIN 5
#define K1 13
#define K2 12
// operatation programer
uint8_t Brightness = 30;
uint8_t pace = 1;
uint8_t serialData = 100;

uint8_t count = 0;
uint8_t time1 = 0;
uint8_t time2 = 0;
uint8_t time3 = 0;
uint8_t co_pat=9;

bool wifi_check = 0;

String ssid = "zh4";  // 路由器名称
String password = "wxg132823";

struct CRGB leds[NUM_LEDS];
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "ntp1.aliyun.com", 60 * 60 * 8, 30 * 60 * 1000);
ESP8266WebServer esp8266_server(80);  // 建立ESP8266WebServer对象，该对象用于响应HTTP请求。监听端口（80）

DNSServer dnsServer;
IPAddress apIP(192, 168, 4, 1);
const char *AP_NAME = "GRD-LAMP";  // wifi名字
const byte DNS_PORT = 53;          // DNS端口号
Ticker ticker;

#include "pattern.h"
#include "wifi.h"
#include "basic.h"

void setup() {
  pinMode(0, INPUT);

  Serial.begin(115200);
  FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);  // GRB ordering is typical
  FastLED.setBrightness(Brightness);

  if (SPIFFS.begin()) {  // 启动闪存文件系统
    Serial.println("SPIFFS Started.");
  } else {
    Serial.println("SPIFFS Failed to Start.");
  }

  initWeb();

  //timeClient.begin();
}

void loop() {
  dnsServer.processNextRequest();
  esp8266_server.handleClient(); // 处理网络请求

  while (Serial.available()) {  // 当串口接收到信息后
    co_pat = Serial.readString().toInt();    // 将接收到的信息使用read读取
    Serial.println(co_pat);    // 然后通过串口监视器输出read函数读取的信息
  }
  if (digitalRead(0) == 0) {
    delay(10);
    if(digitalRead(0)==0)
    co_pat++;
    Serial.printf("co_pat %d", co_pat);
  }
 switchpattern();
 
  
}
